package history.alibaba1.problem1;

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int allCount = sc.nextInt();
        sc.nextLine();
        while(sc.hasNext()){
            int curLen = sc.nextInt();
            sc.nextLine();
            int[] curArray = new int[curLen];
            String[] curStringArray = sc.nextLine().split(" ");
            for(int i = 0; i < curLen; i++){
                curArray[i] = Integer.parseInt(curStringArray[i]);
            }
            System.out.println("当前队列: " + Arrays.toString(curArray));
            System.out.println(getMaxLen(curArray));
        }
    }
    public static int getMaxLen(int[] curArray){
        if(curArray.length == 0) return 0;
        if(sum(curArray) == curArray.length) return curArray.length - 1;
        int pre = 0; // 前一段被分割的长度
        int cur = 0; // 后一段
        int res = 0;
        for(int i: curArray){
            if(i == 1){
                cur++;
                res = Math.max(res, cur + pre);
            }else{
                pre = cur;
                cur = 0;
                res = Math.max(res, cur + pre);
            }
        }
        return res;
    }
    public static int sum(int[] curArray){
        int res = 0;
        for(int i : curArray){
            res += i;
        }
        return res;
    }
}
